Skip to content

在 EZXR AR Glasses 中接入

基于 EZXR AR Glasses 头显设备,提供云定位算法能力

1. 获取SDK

插件下载地址:通过 git 方式导入,详见下文。
版本支持: Unity2020 及以上

2. 更新说明

  • V 2.7.3
    基于 EZXR AR Glasses 头显设备,提供云定位算法能力

3. 接入流程

本文示例代码是基于 Unity2022 版本
  1. 创建新工程或在开发工程中添加 SDK。
  1. 导入SDK。
  • 打开“菜单/Window/Package Manager”
  • 点击"➕"->“Add package from git URL” alt textalt text
  • 选择 sample->点击“import” alt text
  1. 工程配置。
  • 打开“ARSDK/Project Settings” alt text
  • 点击“Fix”,修复所有设置。 alt text

3.1 场景说明

打开场景 EZXRSpatialComputingSample alt text

设置云定位地址,启动自动定位,其中

  • locRequestURL:string,云定位地址
  • requestLocMode: stuct, 云定位模式 alt text

添加引用 SpatialComputingDemo 脚本,并设置其参数, 参数解释见下图。 alt text

2. 示例代码

示例代码脚本 SpatialComputingDemo.cs

csharp
  //启动AR
  //1.拷贝算法文件至可读路径下)
  //2.初始化VPS,成功后默认自动云定位
  
private CopyStreamingAssets m_CopyStreamingAssets;

void Start()
{
    if (m_CopyStreamingAssets != null)
    {
        m_CopyStreamingAssets.OnCopyCompleted += OnCopyCompleted;
    }
}

private void OnDestroy()
{
    if (m_CopyStreamingAssets != null)
    {
        m_CopyStreamingAssets.OnCopyCompleted -= OnCopyCompleted;
    }
}

void OnCopyCompleted(string assetPath)
{
    EZXRSpatialComputingManager.Instance.startSCLocSession(assetPath);
}
csharp
//监听云定位结果
public GameObject displayModel;
private bool modelShowing = false;

void Start()
{
  if(displayModel) {
      displayModel.SetActive(false);
  }
  modelShowing = false;

  InvokeRepeating("checkingLocResults", 1.0f, 1.0f);
}  

private void checkingLocResults() {
  showLocResultStatus();
  showModel();
}

private void showLocResultStatus() {
  if (locResultLabel != null && EZXRSpatialComputingManager.Instance != null)
  {
      var status = EZXRSpatialComputingManager.Instance.currentVpsResultState.vps_result_status;
      var timestamp = EZXRSpatialComputingManager.Instance.currentVpsResultState.t_s;
      locResultLabel.text = $"LocResult : {status}\n    时间戳:{timestamp:F3}";
  }
}

private void showModel() {
  if(EZXRSpatialComputingManager.Instance != null && displayModel != null && !modelShowing) 
  {
      if(EZXRSpatialComputingManager.Instance.currentVpsResultState.vps_result_status == LOCSTATUS.SUCCESS){
          displayModel.SetActive(true);
          modelShowing = true;
      }
  }
}

3.2 必要参数说明

EZXR.Glass.SpatialComputing.EZXRSpatialComputingManager, 算法的参数及状态相关数据。

  • currentVpsResultState : SC_VPSResultState,云定位结果,相关结构体参数见下图。
csharp
  //SC_VPSResultState
  public struct SC_VPSResultState
  {
      public double t_s; //unix时间戳,以s为单位,精确到小数点后3或4位
      public LOCSTATUS vps_result_status;
  }
  public enum LOCSTATUS
  {
      SUCCESS = 0x01, //定位成功,返回pose等信息
      FAIL_UNKNOWN = 0x10, //定位失败,走完了定位算法流程,但是图像无法定位到给定地图中
      FAIL_MATCH = 0x11, //定位失败,具体原因1 hy: not used
      FAIL_INLIER = 0x12, //定位失败,具体原因2 hy: not used
      INVALID_DEVICEINFO = 0x20, //数据不合法,传入的protobuf.deviceInfo不符合规范
      INVALID_LOCALIZER = 0x21, //数据不合法,部署阶段的localizer未成功初始化
      INVALID_IMAGE = 0x22, //数据不合法,传入的图像或protobuf.deviceInfo中出现不被接受的图像格式(仅接收通道数为1或3,且类型为CV_8U或CV_8UC3的图像)
      INVALID_IMAGE_PROTO_MATCH = 0x23, //数据不合法,传入的图像文件长度,与protobuf.deviceInfo中记录的图像字节数不匹配
      INVALID_MESSAGE = 0x24, //传入的message不合法
      FAIL_SUMMARY_UNKNOWN = 0x30, //hy: not used
      FAIL_SUMMARY_NOMAP = 0x31 //未加载完成可用的summary map hy: not used
  }

4. 建议说明

  • 开发时,虚拟内容请参考建图产物(Mesh 或点云文件)进行摆放;